import React, { useImperativeHandle } from "react";
import { Form, Input } from 'antd';
import { IOuterFilterProps } from "vendor/components/pro-table";

export const Filter: IOuterFilterProps["FilterContent"] =React.forwardRef(({doSearch}, actionRef) => {
    const [ form ] = Form.useForm();

    useImperativeHandle(actionRef, () => ({
        getFormData: () => new Promise((resolve, reject) => {
            form.validateFields().then((data) => {
                resolve(data);
            }).catch((e) => {
                reject(new Error("请检查参数"));
            });
        })
    }));

    return (
        <Form layout="inline" form={form}>
            <Form.Item label="名称" name="name">
                <Input />
            </Form.Item>
        </Form>
    )
});

// 更多过滤条件
export const MoreFilter: IOuterFilterProps["FilterContent"] = React.forwardRef(({doSearch}, actionRef) => {
    const [ form ] = Form.useForm();

    useImperativeHandle(actionRef, () => ({
        getFormData: () => new Promise((resolve, reject) => {
            form.validateFields().then((data) => {
                resolve(data);
            }).catch((e) => {
                reject(new Error("请检查参数"));
            });
        })
    }));

    return (
        <Form layout="horizontal" form={form}>
            <Form.Item label="年龄" name="age">
                <Input />
            </Form.Item>
        </Form>
    )
});